package com.xbs.controller.hitchhiking;

import java.io.IOException;

import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xbs.controller.base.BaseServlet;
import com.xbs.entity.CarModelEntity;
import com.xbs.entity.CityEntity;
import com.xbs.entity.HitchEntity;

import com.xbs.service.hitchhiking.HitchService;
@WebServlet("/hitchhiking/hitch")
public class HitchServlet extends BaseServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		HitchService hitchservie = new HitchService();
		/**
		 * 1.查询城市
		 */
		String citys = "'北京','广州','杭州','上海','深圳'";
		List<CityEntity> citylst = hitchservie.getCity(citys);
		req.setAttribute("citylst", citylst);
		
		/**
		 * 2.查询所有品牌
		 */
		List<CarModelEntity> carmodellst = hitchservie.getCar();
		req.setAttribute("carmodellst",carmodellst );
		
		/**
		 * 3.根据不同的城市，车型，时间查询顺风车
		 */
		String hcity =req.getParameter("cityname");
		String htype = req.getParameter("cartype");
		String htime = req.getParameter("getdate");
		hcity= (hcity==null||hcity.equals(""))?"":hcity;
		htype= (htype==null||htype.equals(""))?"":htype;
		htime= (htime==null||htime.equals(""))?"":htime;
		
		List<HitchEntity> hitchlst = hitchservie.getHitch(hcity,htype,htime);
		if(hitchlst.size()<1){
			String str = "暂无顺风车，可以电话预定或者考虑自驾租车哦！";
			req.setAttribute("str", str);
		}
		req.setAttribute("hitchlst", hitchlst);
		req.setAttribute("htime", htime);
		req.setAttribute("hcity", hcity);
		req.setAttribute("htype", htype);
		
		//转发
		forward("businessview/hitchhiking");
	}
}
